using UnityEngine;
using System.Collections;

public class SceneGame_Harpoon : MonoBehaviour
{
	
	public  float      MinDistance;
	public  float      MaxDistance;
	public  float      MinVelocity;
	public  float      MaxVelocity;
	private bool       _Attack;
	private GameObject _Player;
	
	public void Start()
	{
		_Player = GameObject.Find("PlayerPrefab");
	}
	
	public void Update()
	{
		float distance = Vector3.Distance(
			_Player.transform.position,
			transform.position
		);
		if (!_Attack)
			if (distance <= MinDistance)
			{
				rigidbody.velocity = new Vector3(
					MaxVelocity,
					0.0f,
					0.0f
				);
				_Attack = true;
			}
			else if (distance <= MaxDistance)
				rigidbody.velocity = new Vector3(
					MinVelocity,
					0.0f,
					0.0f
				);
	}
	
	public void OnTriggerEnter(Collider collider)
	{
		if (collider.name == "Wall")
		{
			rigidbody.velocity = Vector3.zero;
			rigidbody.constraints = RigidbodyConstraints.FreezeAll;
		}
	}
	
}